<?php

// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://demo.thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库：https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库：https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------

namespace app\monitor\controller;

use app\admin\service\NodeService;
use library\Controller;
use library\tools\Data;
use think\Console;
use think\Db;
use think\exception\HttpResponseException;
use think\Request;
use app\monitor\model\JkList;
/**
 * 监控系统模块
 * Class Monitor
 * @package app\monitor\controller
 */
class Mlist extends Controller
{
    /**
     * 指定当前数据表
     * @var string
     */
    public $table = 'JkList';
    /**
     * 现场勘察采集
     * @auth true
     * @menu true
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function index()
    {
       $this->fetch();
    }
    /**
     * 添加系统用户
     * @auth true
     * @menu true
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    //图片上传
    public function picuploads(Request $request){
        $status = 0;
        $data = [];
        if ($request->Method()== 'POST') {
            $file = $request->file('file');
            // 移动到框架应用根目录/upload/ 目录下
            $info = $file->move('upload');
            if ($info){
                //把反斜杠(\)替换成斜杠(/) 因为在windows下上传路是反斜杠径
                $getSaveName=str_replace("\\","/",$info->getSaveName());
                $fileUrl = '/upload/'.$getSaveName;
                $status = 1;
                $data['url'] = $fileUrl;
                $message = '上传成功';
            }else{
                $message = "上传失败 ".$file->getError();
            }
        } else {
            $message = "参数错误";
        }
        return json(['stauts'=>$status,'msg'=>$message,'data'=>$data]);
    }
    /**
     * 添加勘察操作
     * @auth true
     * @menu true
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    //添加勘察操作
    public function add(){
        if ($this->request->isPost()){


        $data=input('post.');
        $data['kctime']=time();
        $data['status']=0;
        $jk=new JkList();
        $rs=$jk->data($data)->save();
        if ($rs){
                return json(['stauts'=>1,'msg'=>"你已上报成功"]);
            }else{
                return json(['stauts'=>0,'msg'=>"系统出错",'url'=>"index"]);
            }
    }else{
            $this->error("非法操作");
        }


}
    /**
     * 我的上报
     * @auth true
     * @menu true
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    //添加勘察操作
    public function myadd(){


        $rs=db('jk_list')->where(['kcr' => session('admin_user.username')])->order('id desc')->paginate(5);
        $this->assign('list',$rs);
        $this->fetch();


    }
    //查看
    public function show(){
        $id=input('id');
        $rs=db('jk_list')->where(['id' => $id])->find();
        if ($rs['kcr']!==session('admin_user.username')){
            $this->error("你无权查看");
        }
        $this->assign('rs',$rs);
        $this->fetch();

    }

}
